const db = require('../config/db').sequelize()
const Article = db.import('../schema/article.js')
Article.sync({force: false});

class ArticleModel{
  /**
   * 创建文章模型
   * @param data
   * @returns {Promise<*>}
   */
  static async createArticle(data){
    return await Article.create({
      title: data.title,
      author: data.author,
      content: data.content,
      category: data.category
    })
  }

  /**
   * 查询文章详情数据
   * @param id {ID}
   * @returns {Promise<Model>}
   */
  static async getArticleDetail(id){
    return await Article.findOne({
      where: {
        id
      }
    })
  }
}

module.exports = ArticleModel